package pong;

import java.awt.Dimension;
import javax.swing.*;  

public class Pelotita extends JLabel{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6580413450496407749L;
	JFrame ventana;
    Thread hilo1;
    int w, h;
    public Pelotita(JFrame vt)
    {
        super(new ImageIcon("bola.JPG"));
        ventana = vt;
        Dimension dim = ventana.getToolkit().getScreenSize();
		w = dim.width;
		h = dim.height;
		System.out.println(w+"-"+h);
        setLayout(null);
    }   
    
    public void run()
    {
        hilo1 = new Thread(){
            public void run(){
            	System.out.println("se mueve");
            	movimiento(14);
            }          
        };
        hilo1.start();  
    }
    
    public void movimiento(int t){
    	 int x = getX();
         int y = getY();
         int[] aux={x,y}; 
         x = aux[0];
         y = aux[1];

         while((x < w) && y>0){
        	 System.out.println(x+","+y);
        	 aux = derechaAbajo(x, y);
        	 try {
				Thread.sleep(t);
			} catch (Exception e) {
				// TODO: handle exception
			}
         }
    }
        
    public int[] derechaArriba(int x, int y){
        int[] res = new int[3];
        setLocation(x, y);
        res[0] = x + 10;
        res[1] = y - 7; 
        res[2] = 1;
        return res;
    }
    
    public int[] izquierdaArriba(int x, int y){
        int[] res = new int[3];
        setLocation(x, y);
        res[0] = x -9;
        res[1] = y - 6; 
        res[2] = 2;
        return res;
    }
    
    public int[] izquierdaAbajo(int x, int y){
        int[] res=new int[3];
        setLocation(x, y);
        res[0] = x -10;
        res[1] = y + 6;   
        res[2] = 3;
        return res;
    }
    
    public int[] derechaAbajo(int x, int y){
        int[] res=new int[3];
        setLocation(x, y);
        res[0] = x +8;
        res[1] = y + 6;   
        res[2] = 4;
        return res;
    }
    
    public void setMovimiento(int c){
        movimiento(c);
    }
    
    public static void main(String[] args) {
		JFrame ventana = new JFrame();
		Dimension dim = ventana.getToolkit().getScreenSize();
		int w = dim.width;
		int h = dim.height;
		Pelotita p = new Pelotita(ventana);
		p.setBounds((int)(w*.2/2), (int)(h*.2/2), w, h);
		p.setVisible(true);
		p.run();
		ventana.setBounds((int)(w*.2), (int)(h*.2), (int)(w*.6), (int)(h*.6));
		ventana.add(p);
		ventana.setVisible(true);
		
	}
   
}

